#pragma once
#ifndef EVENTLOOPTHREADPOOL_H
#define EVENTLOOPTHREADPOOL_H
#include "NonCopyable.h"
#include <functional>
#include <string>
#include <vector>
#include <memory>
namespace mymuduo {

class EventLoop;
class EventLoopThread;

class EventLoopThreadPool : NonCopyable {
public:
    using ThreadInitCallback = std::function<void(EventLoop*)>;

    EventLoopThreadPool(EventLoop* baseloop, const std::string& name);
    ~EventLoopThreadPool();

    void setThreadNum(int numThreads) {numThreads_ = numThreads;}
    void start(const ThreadInitCallback& cb = ThreadInitCallback());

    // 如果工作中在多线程中，baseloop 默认以轮训的方式分配 channel 给 subloop
    EventLoop* getNextLoop();
    std::vector<EventLoop*> getAllLoops();
    bool started() const {return started_;}
    const std::string name() const {return name_;}
    
private:

    EventLoop *baseloop_;
    std::string name_;
    bool started_;
    int numThreads_;
    int next_;
    std::vector<std::unique_ptr<EventLoopThread>> threads_;
    std::vector<EventLoop*> loops_; 
};

}

#endif